<template>
  <div class="comment-reply">
     <!-- 导航栏 -->
     <van-nav-bar class="page-nav-bar">
       <span slot="title">
         {{ curComment.reply_count ? `有${curComment.reply_count}条回复`:'暂无回复' }}
       </span>
       <template #right>
         <van-icon name="close" @click="$emit('close')"></van-icon>
       </template>
     </van-nav-bar>
     <!-- 当前评论项 -->
     <van-cell class="page-bg" title="评论项内容"></van-cell>
     <comment-item :comment="curComment"></comment-item>
    
    <!-- 回复列表 -->
    <van-cell class="page-bg" title="回复列表"></van-cell>
    <comment-list 
      :list="commentReplyList"
      type='c' 
      :source-id="curComment.com_id"
    ></comment-list>
    
    <!-- 评论回复 -->
    <van-popup v-model="commentReplyShow"  position="bottom">
      <comment-post 
        type='c' 
        :target="curComment.com_id"
        @update-list="updateList"
      ></comment-post>  
    </van-popup>

    <!-- 底部区域 -->
    <div class="reply-bottom">
      <van-button
        class="write-btn"
        size="small"
        round
        @click="commentReplyShow=true"
      >写评论</van-button>
    </div>
    <!-- /底部区域 -->

  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommentPost from './comment-post.vue'
export default {
  name: 'CommentReply',
  components: {CommentItem,CommentPost, CommentList},
  props: {
    // 当前评论项信息
    curComment:{
      type:Object,
      required:true
    }
  },
  data () {
    return {
      commentReplyShow:false,
      commentReplyList:[]
    }
  },
  methods: {
    updateList(val){
      this.commentReplyList.unshift(val.new_obj)
      this.commentReplyShow = false
      this.curComment.reply_count++
    }
  }
}
</script>
<style scoped lang="less">
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}

.reply-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .write-btn {
    width: 60%;
  }
}
.page-bg{
  background-color: #fafafa;
}
</style>